package cn.bocai.pc.web.interceptors;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.bocai.pc.util.PCConstants;

public class frontInterceptor implements HandlerInterceptor  {  
	
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {  
      //  后台session控制  
        Object user=request.getSession().getAttribute("baUserLogin");  
       /* String returnUrl = request.getRequestURI();  */
        if(null==user){  
                response.setContentType("text/html");  
                response.setCharacterEncoding("utf-8");  
                PrintWriter out = response.getWriter();    
                StringBuilder builder = new StringBuilder();    
                builder.append("<script type=\"text/javascript\" charset=\"UTF-8\">");    
                builder.append("alert(\"请求超时，请重新登陆！\");");    
                builder.append("window.location.href=\"/"+PCConstants.SKIP_BA+"/login.jsp\";");    
                builder.append("</script>");    
                out.print(builder.toString());    
                out.close(); 
              /*  request.getRequestDispatcher("/login.jsp").forward(request, response); */
                return false;  
        }  else {
        	 return true;  
		}
        
    }  
  
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception {  
          
    }  
  
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o, Exception e) throws Exception {  
          
    }  
}